#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define R register
#define L long
#define LL long long
#define I inline
#define U unsigned

I LL read()
{
	R LL x;R char f;R char c;
	for (f=0; (c=getchar())<'0'||c>'9'; f=c=='-');
	for (x=c-'0'; (c=getchar())>='0'&&c<='9'; x=(x<<3)+(x<<1)+c-'0');
	return f?-x:x;
}
struct stu
{
    char name[100];
    int xb;
    char used;
};
struct stu stus[1000];




int main()
{
    int n=read();
    for(int i=0;i<n;++i)
        scanf("%d%s",&stus[i].xb,stus[i].name);
    for(int i=0;i<n;++i)
        for(int j=n-1;j>i;--j)
            if(!stus[j].used&&stus[j].xb!=stus[i].xb)
            {
                printf("%s %s\n",stus[i].name,stus[j].name),stus[j].used=1;
                break;
            }
    
 	return 0;
}
